// 取元素 1.退出按钮 2.一级菜单 3.二级菜单 4.初始化按钮
const logoutBtn = document.querySelector('.logout')
const oneList = document.querySelectorAll('.nav>li>a')
const subList = document.querySelectorAll('.nav ul a')
const initBtn = document.querySelector('.init')

// 退出按钮事件
logoutBtn.addEventListener('click', () => {
  if (confirm('您确定退出吗')) {
    localStorage.removeItem('CMStoken87')
    location.href = 'login.html'
  }
})

// 一级菜单  i.nextElementSibling.classList.toggle('show')
oneList.forEach(i => i.addEventListener('click', () => $(i).next().fadeToggle(800)))

// 二级菜单
subList.forEach(i =>
  i.addEventListener('click', () => {
    const beforeA = document.querySelector('.nav ul a.active')
    beforeA.classList.remove('active')
    i.classList.add('active')
  })
)

// 初始化 添加数据
initBtn.addEventListener('click', async () => {
  const result = await axiosFn('/init/data')
  console.log(result)
})
